/**
 * 
 */
package com.optimus.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;

import com.optimus.model.mapped.CategoryBean;

/**
 * @author Optimus
 * 
 */
public class CategoryDAOImpl extends SimpleJdbcDaoSupport implements IdNameEntityDAO<CategoryBean>
{

	@Override
	public void insertIntoDB(CategoryBean entity)
	{
		String sqlCommand = "insert into category (category_id, category_name) values (?, ?)";
		getJdbcTemplate().update(sqlCommand,
				new Object[] { entity.getId(), entity.getName() });
	}

	@Override
	public CategoryBean selectEntityFromDbById(int id)
	{
		String sqlCommand = "SELECT * FROM category WHERE customer_id=?";

		return (CategoryBean) getJdbcTemplate().queryForObject(sqlCommand,
				new Object[] { Integer.valueOf(id) }, new RowMapper<CategoryBean>()
				{
					public CategoryBean mapRow(ResultSet resultSet, int rowNum) throws SQLException
					{
						return new CategoryBean(resultSet.getInt("category_id"), resultSet
								.getString("category_name"));
					}
				});
	}

}
